package com.nowcoder.community.util;

public class RedisKeyUtil {

    // 登录时验证码的拥有者，存验证码 kaptcha:login:(owner) -> string
    public static String getKaptchaKey(String owner) {
        return "kaptcha:login:" + owner;
    }

    // 登陆凭证 ticket:login:(ticket) -> string
    public static String getLoginTicketKey(String ticket) {
        return "ticket:login:" + ticket;
    }

    // 找回密码时邮箱的拥有者 forget:email:(owner) -> string
    public static String getForgetPasswordEmailKey(String owner) {
        return "forget:email:" + owner;
    }

    // 找回密码时验证码的拥有者 forget:code:(owner) -> string
    public static String getForgetPasswordCodeKey(String owner) {
        return "forget:code:" + owner;
    }

    // （帖子或评论）的点赞数 like:(post/comment):(id) -> set(userId)
    public static String getEntityLikeKey(int entityType, int entityId) {
        return "like:" + ((entityType == 1) ? "post:" : "comment:") + entityId;
    }

    // 用户的获赞数 like:user:(userId) -> int
    public static String getUserLikeKey(int userId) {
        return "like:user:" + userId;
    }

    // 用户的关注 idol:(userId) -> zset(idolId, time)
    public static String getIdolKey(int userId) {
        return "idol:" + userId;
    }

    // 用户的粉丝 follower:(userId) -> zset(followerId, time)
    public static String getFollowerKey(int userId) {
        return "follower:" + userId;
    }

    // 统计单日UV(Unique Visitor) uv:(date) -> HyperLogLog
    public static String getUVKey(String date) {
        return "uv:" + date;
    }

    // 统计单日DAU(Daily Active User) dau:(date) -> bitmap
    public static String getDAUKey(String date) {
        return "dau:" + date;
    }

    // 统计连续多日DAU(Daily Active User) dau:(start):(end) -> bitmap
    public static String getDAUKey(String start, String end) {
        return "dau:" + start + ":" + end;
    }

    // 存储需要被定时任务更新score的帖子的id score:post -> set(postId)
    public static String getPostScoreKey() {
        return "score:post";
    }

    // 缓存用户信息 user:(userId) -> User对象
    public static String getUserObjectKey(int userId) {
        return "user:" + userId;
    }

    // 缓存热帖 hotpost:(limit):(offset) -> List<DiscussPost>
    public static String getHotPostKey(int limit, int offset) {
        return "hotpost:" + limit + ":" + offset;
    }

}
